<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
class Crontab extends Controller{
	//根据设置改变客户状态
	public function releaseCustomer(){
		//释放时间
		$releaseTime = Db::name('webset')->where(['name'=>'release_customer'])->value('values');
		$where['status'] = array('in',[6,9]);
		Db::name('member')->where($where)->where(function($query)use($releaseTime){
			$query->where('second_relation',0)->whereTime('entry_time','<',strtotime("-".$releaseTime." day",time()));
		})->update(['status'=>8]);
		Db::name('member')->where($where)->where(function($query)use($releaseTime){
			$query->where('second_relation','<>',0)->whereTime('second_time','<',strtotime("-".$releaseTime." day", time()));
		})->update(['status'=>8]);
	}
	public function accountOverdue(){
		// 逾期
		DB::name('account')
			->where(['status'=>0,'source'=>0])
			->whereTime('finish_time',"<",time())
			->update(['status'=>2,'abnormal'=>1]);
		// 坏账
		DB::name('account')
			->where(['status'=>2,'source'=>0])
			->whereTime('finish_time',"<",strtotime("-3 month"))
			->update(['status'=>6,'abnormal'=>1]);
	}
}
